#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include <math.h>

int is_prime(int x)
{
    for (int i = 2; i <= sqrt(x); i++)
    {
        if (x % i == 0)
            return 0;
    }
    return 1;
}

int main()
{
    int a, b;
    scanf("%d%d", &a, &b);

    int arr[5] = { 0 };
    if (a == 5)
        printf("5\n");
    if (a <= 7 && b >= 7)
        printf("7\n");
    if (a <= 11 && b >= 11)
        printf("11\n");
    for (arr[0] = 1; arr[0] <= 9; arr[0] += 2)
    {
        for (arr[1] = 0; arr[1] <= 9; arr[1]++)
        {
            int temp = 100 * arr[0] + 10 * arr[1] + arr[0];
            if (temp >= a && temp <= b)
            {
                if (is_prime(temp))
                    printf("%d\n", temp);
            }
            else
                continue;
        }
    }
    for (arr[0] = 1; arr[0] <= 9; arr[0] += 2)
    {
        for (arr[1] = 0; arr[1] <= 9; arr[1]++)
        {
            for (arr[2] = 0; arr[2] <= 9; arr[2]++)
            {
                int temp = 10000 * arr[0] + 1000 * arr[1] + 100 * arr[2] + 10 * arr[1] + arr[0];
                if (temp >= a && temp <= b)
                {
                    if (is_prime(temp))
                        printf("%d\n", temp);
                }
                else
                    continue;
            }

        }
    }
    for (arr[0] = 1; arr[0] <= 9; arr[0] += 2)
    {
        for (arr[1] = 0; arr[1] <= 9; arr[1]++)
        {
            for (arr[2] = 0; arr[2] <= 9; arr[2]++)
            {
                for (arr[3] = 0; arr[3] <= 9; arr[3]++)
                {
                    int temp = 1000000 * arr[0] + 100000 * arr[1] + 10000 * arr[2] + 1000 * arr[3] + 100 * arr[2] + 10 * arr[1] + arr[0];
                    if (temp >= a && temp <= b)
                    {
                        if (is_prime(temp))
                            printf("%d\n", temp);
                    }
                    else
                        continue;
                }

            }

        }
    }
    return 0;
}